package cn.jinjie.day05.test1;

public class Test06 {
    public static void main(String[] args) {
        int[] arr = {1, 3, 6, 9, 10, 18, 25, 39, 45, 69};
        int num = 18;
        System.out.println(eFSearch(arr, num) < 0 ? "没找到" : "找到了" + num + "的索引为:" + eFSearch(arr, num));
    }

    public static int eFSearch(int[] arr, int num) {
        int min = 0;
        int max = arr.length - 1;
        while (min <= max) {
            int mid = (min + max) / 2;
            if (num > arr[mid]) {
                min = mid + 1;
            } else if (num < arr[mid]) {
                max = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
